package com.lzxuni.modules.productdisplay.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lzxuni.common.utils.R;
import com.lzxuni.common.utils.StringUtils;
import com.lzxuni.common.utils.UuidUtil;
import com.lzxuni.modules.common.controller.BaseController;
import com.lzxuni.modules.common.entity.FileEntity;
import com.lzxuni.modules.common.entity.PageData;
import com.lzxuni.modules.common.entity.PageParameter;
import com.lzxuni.modules.common.entity.Tree;
import com.lzxuni.modules.common.service.FileEntityService;
import com.lzxuni.modules.dataAcquisition.service.ChainService;
import com.lzxuni.modules.enterprise.service.EnterpriseInfoService;
import com.lzxuni.modules.informationpublish.entity.InformationPublishPressRelease;
import com.lzxuni.modules.productdisplay.entity.ProductDisplay;
import com.lzxuni.modules.productdisplay.service.ProductDisplayService;
import com.lzxuni.modules.system.service.BaseAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author llj
 * @since 2019-06-27
 */
@RestController
@RequestMapping("/ProductDisplay")
public class ProductDisplayController extends BaseController {
    @Autowired
    private ProductDisplayService productDisplayService;
    @Autowired
    private FileEntityService fileEntityService;
    @Autowired
    private BaseAreaService baseAreaService;

   /* @RequestMapping("/Index")
    public ModelAndView list() throws Exception {
        List<ProductDisplay> list = productDisplayService.list(new QueryWrapper<ProductDisplay>().orderByDesc("create_time").last("limit 8"));
        ModelAndView mv = new ModelAndView("/ProductDisplay");
        List list1 =null;
        for (int i= 0;i<list.size();i++){
            FileEntity fileEntity = new FileEntity();
            String id = list.get(i).getYwId();
            fileEntity.setYwId(id);
            fileEntity.setYwType("demopic");
            list1 = fileEntityService.queryListByFileEntity(fileEntity);
            list.get(i).setFileEntities(list1);
        }
        mv.addObject("list1",list1);
        mv.addObject("list",list);
        return mv;
    }
    @RequestMapping("/One")
    public ModelAndView insert(String ywId) throws Exception {
        System.out.println(ywId);
        String Province = null;
        String City = null;
        String County = null;
        String Town = null;
        String Village = null;
        ProductDisplay productDisplay = productDisplayService.getById(ywId);
        if (productDisplay.getProvinceId()!=null&&productDisplay.getProvinceId()!=""){
            Province =baseAreaService.getById(productDisplay.getProvinceId()).getAreaName();
        }
        if (productDisplay.getCityId()!=null&&productDisplay.getCityId()!=""){
            City =baseAreaService.getById(productDisplay.getCityId()).getAreaName();
        }
        if (productDisplay.getCountyId()!=null&&productDisplay.getCountyId()!=""){
            County =baseAreaService.getById(productDisplay.getCountyId()).getAreaName();
        }
        if (productDisplay.getTownId()!=null&&productDisplay.getTownId()!=""){
            Town =baseAreaService.getById(productDisplay.getTownId()).getAreaName();
        }
        if (productDisplay.getVillageId()!=null&&productDisplay.getVillageId()!=""){
            Village =baseAreaService.getById(productDisplay.getVillageId()).getAreaName();
        }
        FileEntity fileEntity = new FileEntity();
        fileEntity.setYwId(ywId);
        fileEntity.setYwType("demopic");
        List list = fileEntityService.queryListByFileEntity(fileEntity);
        ModelAndView mv = new ModelAndView("/productdisplay_xx");
        mv.addObject("Province",Province);
        mv.addObject("City",City);
        mv.addObject("County",County);
        mv.addObject("Town",Town);
        mv.addObject("Village",Village);
        mv.addObject("productDisplay",productDisplay);
        mv.addObject("list",list);
        return mv;
    }*/

    //曝光台
//    @RequestMapping("/NewExposureStage.html")
    @RequestMapping(value = "/Index",method = RequestMethod.GET)
    public ModelAndView newexposureStage() throws Exception {
        ModelAndView mv = new ModelAndView("/ProductDisplay");
        int count = productDisplayService.count(new QueryWrapper<ProductDisplay>());
        List<ProductDisplay> list = productDisplayService.list(new QueryWrapper<ProductDisplay>());
        List list1 =null;
        for (int i= 0;i<list.size();i++){
            FileEntity fileEntity = new FileEntity();
            String id = list.get(i).getYwId();
            fileEntity.setYwId(id);
            fileEntity.setYwType("demopic");
            list1 = fileEntityService.queryListByFileEntity(fileEntity);
            list.get(i).setFileEntities(list1);
        }
        mv.addObject("list1",list1);
        //mv.addObject("list",list);
        mv.addObject("count", count);
        return mv;
    }

    //曝光台详细页
    @RequestMapping(value = "/One/{ywId}",method = RequestMethod.GET)
    public ModelAndView newexposureStagedetails(@PathVariable String ywId) throws Exception {
        System.out.println(ywId);
        String Province = null;
        String City = null;
        String County = null;
        String Town = null;
        String Village = null;
        ProductDisplay productDisplay = productDisplayService.getById(ywId);
        if (productDisplay.getProvinceId()!=null&&productDisplay.getProvinceId()!=""){
            Province =baseAreaService.getById(productDisplay.getProvinceId()).getAreaName();
        }
        if (productDisplay.getCityId()!=null&&productDisplay.getCityId()!=""){
            City =baseAreaService.getById(productDisplay.getCityId()).getAreaName();
        }
        if (productDisplay.getCountyId()!=null&&productDisplay.getCountyId()!=""){
            County =baseAreaService.getById(productDisplay.getCountyId()).getAreaName();
        }
        if (productDisplay.getTownId()!=null&&productDisplay.getTownId()!=""){
            Town =baseAreaService.getById(productDisplay.getTownId()).getAreaName();
        }
        if (productDisplay.getVillageId()!=null&&productDisplay.getVillageId()!=""){
            Village =baseAreaService.getById(productDisplay.getVillageId()).getAreaName();
        }
        FileEntity fileEntity = new FileEntity();
        fileEntity.setYwId(ywId);
        fileEntity.setYwType("demopic1");
        List list = fileEntityService.queryListByFileEntity(fileEntity);
        ModelAndView mv = new ModelAndView("/productdisplay_xx");
        mv.addObject("Province",Province);
        mv.addObject("City",City);
        mv.addObject("County",County);
        mv.addObject("Town",Town);
        mv.addObject("Village",Village);
        mv.addObject("productDisplay",productDisplay);
        mv.addObject("list",list);
        return mv;
    }
    //按类型列表页分页
    @RequestMapping("/listDoType.html")
    public Object typelistDo(String pagination,String newsType) throws Exception {
        PageParameter pageParameter = JSON.parseObject(pagination.replaceAll("&＃39;", "\""), PageParameter.class);
        PageData pageData = getPageData(productDisplayService.queryPagebm(pageParameter));
        return pageData;
    }
}

